package com.botarena.client.battle;

import com.botarena.client.ui.GomokuVisualizer;
import com.botarena.shared.BattlePreviewInfo;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class BattlePreview extends VerticalPanel {
	
	public BattlePreview(BattlePreviewInfo result){
		setStyleName("contentElementFull");
		
		Panel info = new VerticalPanel();
		info.setStyleName("infoBox");
		
		Panel fightingBots = new HorizontalPanel();
		fightingBots.add(new Label(result.getBot1Name()));
		Label labelX = new Label("X");
		labelX.setStyleName("symbol_cross");
		labelX.setHorizontalAlignment(ALIGN_CENTER);
		labelX.setWidth("20px");
		fightingBots.add(labelX);
		Label labelVS = new Label(" vs ");
		labelVS.setHorizontalAlignment(ALIGN_CENTER);
		labelVS.setWidth("40px");
		fightingBots.add(labelVS);
		Label labelO = new Label("O");
		labelO.setStyleName("symbol_circle");
		labelO.setHorizontalAlignment(ALIGN_CENTER);
		labelO.setWidth("20px");
		fightingBots.add(labelO);
		fightingBots.add(new Label(result.getBot2Name()));
		fightingBots.setStyleName("title2");
		
		Label battleDate = new Label("Date: " + result.getDate());
		battleDate.setStyleName("title4");
		Label winner = new Label("Winner: " + getWinnerName(result));
		winner.setStyleName("title4");
		Label justification = new Label("Justification: " + result.getJustification());
		justification.setStyleName("title4");
		
		add(fightingBots);
		
		info.add(battleDate);
		info.add(winner);
		info.add(justification);
		add(info);
		
		Panel main = new HorizontalPanel();
		main.add(new GomokuVisualizer(result.getProcess()));
		
		ScrollPanel scroll = new ScrollPanel(new FightMovesVisualizer(result.getProcess()));
		scroll.setStyleName("movesList");
		main.add(scroll);
		
		add(main);
		
	}
	
	private String getWinnerName(BattlePreviewInfo result){
		if (result.getWinner() == 1)
			return result.getBot1Name();
		if (result.getWinner() == 2)
			return result.getBot2Name();
		else
			return "no winner (draw)";
	}

}
